package cn.gistone.visualeditor.utils;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value="结果对象")
public class AjaxResult {
    @ApiModelProperty("操作结果是否成功")
    private Boolean success = true;
    @ApiModelProperty("操作结果的提示信息")
    private String msg = "操作成功";
    @ApiModelProperty("返回的操作数据")
    private Object data;

    public AjaxResult(Boolean success,String msg) {
        this.success = success;
        this.msg = msg ;
    }

    /**
     * 失败
     * @param msg
     * @return
     */
    public static AjaxResult fail(String msg){
        return new AjaxResult(false,msg);
    }

    /**
     * 成功
     * @return
     */
    public static AjaxResult ok(){
        return new AjaxResult();
    }

    public static AjaxResult ok(Object data){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setData(data);
        return ajaxResult;
    }
}
